package kizzo.particle_system 
{
	import away3d.entities.Sprite3D;
	import away3d.materials.TextureMaterial;
	import flash.events.Event;
	import flash.geom.Vector3D;
	/**
	 * ...
	 * @author kizzo
	 */
	public class Particle 
	{		
		private var sprite_3d:Sprite3D;		
		
		public var start_position:Vector3D;
		public var end_position:Vector3D;
		public var num_steps:int;
		private var current_step:int;
		
		
		
		public function Particle(material:TextureMaterial) 
		{
			this.sprite_3d = new Sprite3D(material, 2 + Math.random() * 5, 2 + Math.random() * 5);			
			Main.get_instance().view_3D.scene.addChild(this.sprite_3d);
			current_step = 0;
			Main.get_instance().addEventListener(Event.ENTER_FRAME, update);
		}
		
		
		
		public function update(e:Event):void
		{
			this.current_step++;
			
			var rel_pos:Number = current_step / num_steps; 
			
			this.sprite_3d.x = start_position.x + (end_position.x - start_position.x) * rel_pos;
			this.sprite_3d.y = start_position.y + (end_position.y - start_position.y) * rel_pos;
			this.sprite_3d.z = start_position.z + (end_position.z - start_position.z) * rel_pos;
			
			if (this.current_step >= num_steps)
			{
				Main.get_instance().view_3D.scene.removeChild(this.sprite_3d);
				Main.get_instance().addEventListener(Event.ENTER_FRAME, update);
			}
		}
		
		
	}

}